/**
 * 
 */
package edu.sjtu.seda.log;

import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author john.zhu
 *
 */
public class LogService {
	private Date date;
	private static final String logPattern = "{0}[{1}][{2}][{3}] {4}";
	private Class clazz;
	
//	public LogService(){
//		
//	}
	
	public LogService(Class clazz){
		this.clazz = clazz;
	}
	
	public void info(String msg){
		System.out.println(MessageFormat.format(logPattern, toDate(),"INFO",Thread.currentThread().getName(),clazz.getSimpleName(),msg));
	}
	
	public void error(String msg){
		System.err.println(MessageFormat.format(logPattern, toDate(),"ERROR",Thread.currentThread().getName(),clazz.getSimpleName(),msg));		
	}
	
	public void debug(String msg){
		System.out.println(MessageFormat.format(logPattern, toDate(),"DEBUG",Thread.currentThread().getName(),clazz.getSimpleName(),msg));
	}
	
	private String toDate(){
		date = new Date();
		return new SimpleDateFormat("MM/dd/yy HH:mm:ss.SSS").format(date);
	}
}
